<template>
	<view class="content">
		<view :class="[isSceneSubject?'content-swapper':'']">
			<view class="content-main" :style="{ height: heightContainer}" v-if="isScene">
				<text class="content-sub">
					{{getSubjectParentDesc}}
				</text>
			</view>
			<view class="edging" v-if="isScene">
				<view @click="toggle" :class="['arrow',foldSubject?'arrow-down':'']"></view>
				<view class="slip"></view>
				<view class="h"></view>
			</view>
			<view class="content-block">
				{{getSubjectNum}}、<text v-if="isScene" class="content-block-light">【{{choiceTypeDesc}}】</text>{{getSubjectDesc}}
			</view>
			<auto-img v-if="subject.contentType=='2'" :src="subject.contentUrl"></auto-img>
			<audio v-if="subject.contentType=='4'" :src="subject.contentUrl"></audio>
			<video v-if="subject.contentType=='3'" :src="subject.contentUrl"></video>
		</view>
		<view v-if="judgeChoiceType == 1 || judgeChoiceType == 2">

			<!-- <view v-for="item in newSubjectChoices" :key="item.choiceId" @click="judgeFlag(radioChange,item.choiceId)">
				<view :class="[item.showClass]">
					<text>{{item.choiceId}}、</text>
					<text class="content-opt">{{item.choiceDesc}}</text>
				</view>
				<auto-img v-if="item.choiceType=='2'" :src="item.contentUrl"></auto-img>
				<audio v-if="item.choiceType=='4'" :src="item.contentUrl"></audio>
				<video v-if="item.choiceType=='3'" :src="item.contentUrl"></video>
			</view> -->
			<radio-group @change="judgeFlag(radioChange,item.choiceId)" v-for="(item,index) in newSubjectChoices" :key="item.choiceId">
				<label :class="[item.showClass]">
					<radio :disabled="showBox" style="transform: scale(0.7)" :value="item.value" :checked="index === current" />
					<text style="margin-top: 4px;">{{item.choiceId}}、{{item.choiceDesc}}</text>
				</label>
				<auto-img v-if="item.choiceType=='2'" :src="item.contentUrl"></auto-img>
				<audio v-if="item.choiceType=='4'" :src="item.contentUrl"></audio>
				<video v-if="item.choiceType=='3'" :src="item.contentUrl"></video>
			</radio-group>


		</view>

		<view v-if="judgeChoiceType == 3">
			<checkbox-group v-for="item in newSubjectChoices" :key="item.choiceId" @click="judgeFlag(checkChange,item.choiceId)">
				<label :class="[item.showClass]">
					<view>
						<checkbox :checked="selectChoice.length>0&&['content-ana-itemcnot','content-ana-itemc'].includes(item.showClass)" :disabled="showBox" style="transform: scale(0.7)" :value="item.value" />
					</view>
					<text style="margin-top: 4px;">{{item.choiceId}}、{{item.choiceDesc}}</text>
					<!-- <text class="contentd-opt"></text> -->
				</label>
				<auto-img v-if="item.choiceType=='2'" :src="item.contentUrl"></auto-img>
				<audio v-if="item.choiceType=='4'" :src="item.contentUrl"></audio>
				<video v-if="item.choiceType=='3'" :src="item.contentUrl"></video>
			</checkbox-group>
			<!-- <view v-for="item in newSubjectChoices" :key="item.choiceId" @click="judgeFlag(checkChange,item.choiceId)">
				<view :class="[item.showClass]">
					<text>{{item.choiceId}}、</text>
					<text class="contentd-opt">{{item.choiceDesc}}</text>
				</view>
				<auto-img v-if="item.choiceType=='2'" :src="item.contentUrl"></auto-img>
				<audio v-if="item.choiceType=='4'" :src="item.contentUrl"></audio>
				<video v-if="item.choiceType=='3'" :src="item.contentUrl"></video>
			</view> -->

		</view>
	</view>
</template>

<script>
	import AutoImg from './AutoImg';
	import {
		isEmpty
	} from '@/utils/index';
	export default {
		components: {
			AutoImg
		},
		data() {
			return {
				foldSubject: false,
				isSceneSubject: true,
				domHeihgt: '',
				heightContainer: '',
			}
		},
		props: {
			subject: {
				type: Object,
				default: function() {
					return {}
				}
			},
			choiceTypeDesc: {
				type: String,
				default: ''
			},
			showBox:{
				type: Boolean,
				default: ''
			}
		},
		computed: {
			isScene() {
				return !isEmpty(this.subject.subjectParentDesc);
			},
			judgeChoiceType() {
				return this.subject.choiceType;
			},
			getSubjectNum() { //题号
				return this.subject.subjectNum;
			},
			getSubjectDesc() { //题目
				return this.subject.subjectDesc;
			},
			getSubjectParentDesc() { //情景题主题描述
				return this.subject.subjectParentDesc;
			},
			getSubjectChoices() { //获取答案选项
				return this.subject.subjectChoices;
			},
			answer() {
				return this.subject.answer;
			},
			current(){
				if(this.subject.selectChoice.length == 0){
					return this.subject.current = -1
				}else if([...this.subject.selectChoice] == 'A'){
					return this.subject.current = 0
				}else if([...this.subject.selectChoice] == 'B'){
					return this.subject.current = 1
				}else if([...this.subject.selectChoice] == 'C'){
					return this.subject.current = 2
				}else if([...this.subject.selectChoice] == 'D'){
					return this.subject.current = 3
				}
			},
			
			selectChoice() { //学生答案
				console.log(this.subject.selectChoice)
				return this.subject.selectChoice;
			},
			// radioChange: function(evt) {
			// 	for (let i = 0; i < this.items.length; i++) {
			// 		if (this.items[i].value === evt.target.value) {
			// 			this.current = i;
			// 			break;
			// 		}
			// 	}
			// },
			newSubjectChoices() {
				const {
					answer,
					selectChoice,
					showAnalyse,
					current
				} = this.subject;
				this.getSubjectChoices.forEach(
					item => {
						if (showAnalyse) {
							if (answer != undefined && answer.find(v => item.choiceId == v) != undefined) { //答案选项
								if (selectChoice != undefined && selectChoice.find(v => item.choiceId == v) != undefined) {
									//正确答案，用户选择
									item.showClass = 'content-ana-itemc'
								} else {
									//正确答案，用户未选择
									item.showClass = this.judgeChoiceType == 3 ? 'content-ana-itemcnot' : 'content-ana-itemc'
									// item.showClass = 'content-itemcnot'
								}
							} else { //错误答案
								if (selectChoice != undefined && selectChoice.find(v => item.choiceId == v) != undefined) {
									item.showClass = 'content-ana-iteme'
								} else {
									item.showClass = 'content-item'
								}
							}
						} else {
							if (item.isChose == 0) { //未选
								item.showClass = 'content-item'
							} else { //已选 == 1
								item.showClass = 'content-itemc'
							}
						}
					}
				)
				return this.getSubjectChoices;
			},
		},
		methods: {
			judgeFlag(callback, param) {
				this.$emit("judgeFlag", {
					callback,
					param
				})
			},
			checkChange(choiceId) {
				this.$emit("checkChange", choiceId)
			},
			radioChange(choiceId) {
				this.$emit("radioChange", choiceId)
			},
			toggle() {
				this.foldSubject = !this.foldSubject;
				if (this.foldSubject) {
					this.dynaHeight();
				} else {
					this.heightContainer = this.domHeihgt + 'px'
				}
			},
			dynaHeight() { //计算隐藏和显示后的标签高度
				this.getHeight();
				let height = this.foldSubject ? this.domHeihgt / 3 : this.domHeihgt;
				// // #ifdef APP-PLUS
				// height = this.domHeihgt/3
				// console.log("22222",this.domHeihgt,height)
				// // #endif
				this.heightContainer = height + 'px'
			},
			getHeight() { //实时获取元素高度
				let dom = uni.createSelectorQuery().selectAll(`.${'content-main'}`);
				dom.boundingClientRect(rect => {}).exec(e => {
					if (e[0][0]) {
						this.domHeihgt = e[0][0].height;
					}
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin: 20upx;
		font-size: 30upx;
		border-radius: 8rpx;
		box-shadow: 0 0 10upx #eaeaea;
		padding: 30upx 30upx;

		&-main {
			display: flex;
			/*height:400upx;*/
			/*flex-wrap: wrap;*/
			// margin-bottom: 20upx;
			overflow: hidden;
		}

		&-block {
			// display: flex;
			/*height:400upx;*/
			/*flex-wrap: wrap;*/
			margin-bottom: 40upx;
			overflow: hidden;
			font-weight: bold;
			margin-top: 10px;

			&-light {
				color: #5ea1f8;
			}
		}

		&-sub {
			color: #000;
			font-weight: bold;
			overflow-y: auto;
		}

		&-swapper {
			margin-bottom: 90upx;
		}

		&-item {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #f4f6f8;
			border-radius: 8rpx;
			color: #000;
		}

		&-itemc {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #5ea1f8;
			color: #fff;
			border-radius: 8rpx;
		}

		&-ana-item {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #f4f6f8;
			border-radius: 8rpx;
			color: #000;
		}

		&-ana-itemc {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #5ea1f8;
			color: #fff;
			border-radius: 8rpx;
		}

		&-ana-itemcnot {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #5ea1f8;
			color: #fff;
			border-radius: 8rpx;
			border: 4upx solid #f1685d;
		}

		&-ana-iteme {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #f1685d;
			color: #fff;
			border-radius: 8rpx;
		}


		&-ico {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			color: #377cfd;
			text-align: center;
			color: #377cfd;
			line-height: 80upx;
		}

		&-icoc {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			text-align: center;
			color: #fff;
			background: #377cfd;
			line-height: 80upx;
		}

		&-opt {
			/*display: inline-block;*/
			/*line-height: 80upx;*/
			line-height: 1.5;
		}

	}

	.contentd {
		margin: 40upx;
		font-size: 30upx;

		&-block {
			margin-bottom: 40upx;
		}

		&-type {
			color: #377cfd;
			font-weight: bold;
		}

		&-sub {
			color: #000;
			font-weight: bold;
		}

		&-item {
			margin: 20upx 0;
			font-size: 26upx;
		}

		&-ico {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			color: #377cfd;
			text-align: center;
			color: #377cfd;
		}

		&-icoc {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			text-align: center;
			color: #fff;
			background: #377cfd;
		}

		&-opt {
			/*display: inline-block;*/
			/*line-height: 80upx;*/
			line-height: 1.5;
		}

	}

	.edging {
		position: relative;
		height: 34upx;
		margin-bottom: 20upx;
	}

	.arrow {
		width: 56upx;
		height: 56upx;
		z-index: 10;
		background-image: url('~@/static/img/mine/arrow.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: absolute;
		// bottom: -32upx;
		right: 40upx;

		&.arrow-down {
			z-index: 10;
			background-image: url('~@/static/img/mine/arrow-down.png');
			background-repeat: no-repeat;
		}
	}

	.slip {
		position: absolute;
		bottom: -16upx;
		left: 0;
		height: 16upx;
		width: 100%;
		background: #eee;

	}

	.h {
		height: 40upx;
		width: 100%;

	}
</style>
